<?php
App::import('Vendor','xtcpdf');
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Nicola Asuni');
$pdf->SetTitle('TCPDF Example 048');
$pdf->SetSubject('TCPDF Tutorial');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');

// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 048', PDF_HEADER_STRING);

// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));

// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

//set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);

//set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

//set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);


// ---------------------------------------------------------

// set font
$pdf->SetFont('helvetica', 'B', 20);

// add a page
$pdf->AddPage();

$pdf->Write(0, $report->title, '', 0, 'L', true, 0, false, false, 0);

$pdf->SetFont('helvetica', '', 8);

// -----------------------------------------------------------------------------

$count = count($rows);
$tbl_head = <<<EOD
<STYLE type="text/css">
	.tableTd {
	   	border-width: 0.5pt; 
		border: solid; 
	}
	.tableTdContent{
		border-width: 0.5pt; 
		border: solid;
	}
	#titles{
		font-weight: bolder;
	}
   
</STYLE>
<table>
	<tr>
		<td><b>List of all cars available in Afha<b></td>
	</tr>
	<tr>
		<td><b>Date:</b></td>
		<td><?php echo date("F j, Y, g:i a"); ?></td>
	</tr>
	<tr>
		<td><b>Number of cars:</b></td>
		<td style="text-align:left">$count</td>
	</tr>
	<tr>
		<td></td>
	</tr>
		<tr id="titles">
			<td class="tableTd">Title</td>
			<td class="tableTd">Year</td>
			<td class="tableTd">Buying Price</td>
			<td class="tableTd">Reg No</td>
			<td class="tableTd">Date</td>
			
		</tr>		
		
</table>
EOD;
$i = 0;
foreach ($rows as $row) {
	$tbl_content .= '<tr>';
	$tbl_content .= '<td class="tableTdContent">' . strtoupper ( $row ['Make'] ['name'] ) . " " . strtoupper ( $row ['Mod'] ['name'] ) . " " . strtoupper ( $row ['Store'] ['title'] ) . '</td>';
	$tbl_content .= '<td class="tableTdContent">' . $row ['Store'] ['year'] . '</td>';
	$tbl_content .= '<td class="tableTdContent">' . $this->Number->format ( $row ['Store'] ['price'], array ('places' => 2, 'before' => 'MYR', 'decimals' => '.', 'thousands' => ',' ) ) . '</td>';
	$tbl_content .= '<td class="tableTdContent">' . $row ['Store'] ['reg_no'] . '</td>';
	$tbl_content .= '<td class="tableTdContent">' . date ( 'Y-m-d', strtotime ( $row ['Store'] ['date'] ) ) . '</td>';
	$tbl_content .= '</tr>';
}
$tbl_close = "</table>";


$pdf->writeHTML($tbl_head.$tbl_content.$tbl_close, true, false, false, false, '');

// -----------------------------------------------------------------------------

//Close and output PDF document
$pdf->Output('example_048.pdf', 'I');
